package org.xtremeobjects.forms.ui.editors;

import org.xtremeobjects.domain.model.Clazz;
import org.xtremeobjects.domain.model.ClazzRepository;
import org.xtremeobjects.domain.model.ddd.Repository;
import org.xtremeobjects.domain.model.ddd.config.ModuleInfoRepository;

import com.google.inject.Inject;

public class ObjectEditorModelFactory {
	
	private ClazzRepository clazzRepository;
	private ModuleInfoRepository moduleInfoRepository;

	@Inject
	public ObjectEditorModelFactory( ClazzRepository clazzRepository, ModuleInfoRepository moduleInfoRepository ) {
		this.clazzRepository = clazzRepository;
		this.moduleInfoRepository = moduleInfoRepository;
	}

	public ObjectEditorModel create(String clazzName, String objectId ) {
		ObjectEditorModel model = null;
		try {
			Clazz clazz = clazzRepository.findOrCreateByName(clazzName);
			Repository repo = moduleInfoRepository.getModuleForClazz(clazz).getRepositoryForClazz(clazz);
			model = new ObjectEditorModel(clazz, repo, objectId);
		} catch (Exception e) {
		}
		return model;
	}
}
